package info.motteke.kurumi.swt;

import info.motteke.mixivoice4j.User;

import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Link;

public class SwtVoiceFavoriteList {

    private final Composite base;

    private final Link title;

    private final Combo list;

    @SuppressWarnings("unused")
    private final SortedSet<User> favorites = new TreeSet<User>();

    public SwtVoiceFavoriteList(Composite parent) {
        base = new Composite(parent, SWT.NONE);

        GridLayout layout = new GridLayout(2, false);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        base.setLayout(layout);
        base.setLayoutData(createLayoutData());
        base.pack(false);
        title = new Link(base, SWT.NONE);
        title.setText("<a>イイネ</a> : ");
        title.setLayoutData(new GridData());
        list = new Combo(base, SWT.READ_ONLY);
        list.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }

    private GridData createLayoutData() {
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalIndent = 0;
        gd.verticalIndent = 0;
        return gd;
    }

    public void addFavorite(Set<User> favorites) {
        list.removeAll();
        for(User user : favorites) {
            list.add(user.getNickName());
        }

        if(list.getItemCount() != 0){
            list.select(0);
        }
    }
}
